﻿#region base
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;
using System.Web.Script.Serialization;

//[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.  
[System.Web.Script.Services.ScriptService]
#endregion

public class MemberShipWebService : System.Web.Services.WebService
{
    #region innit
    Hachi.Controllers.CategoriesController catectr = new Hachi.Controllers.CategoriesController();
    public MemberShipWebService () {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod]
    public string HelloWorld()
    {
        return "Hello World";
    }
    #endregion

    #region login
    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public string login(string user, string pass)
    {
        List<hachiModel.PR_Category> cates = catectr.GetCategoriesCanUse();
        // Return JSON data
        //string[][] JaggedArray = new string[cates.Count][];
        JavaScriptSerializer js = new JavaScriptSerializer();
        string strJSON = js.Serialize(cates.Select(s => new {s.ParentID, s.CategoryID, s.CategoryCode }));
        return strJSON;
    }
    #endregion

    #region logout
    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public string logout(string user)
    {
        List<hachiModel.PR_Category> cates = catectr.GetCategoriesCanUse();
        // Return JSON data
        //string[][] JaggedArray = new string[cates.Count][];
        JavaScriptSerializer js = new JavaScriptSerializer();
        string strJSON = js.Serialize(cates.Select(s => new { s.ParentID, s.CategoryID, s.CategoryCode }));
        return strJSON;
    }
    #endregion

    #region create user
    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public string createUser(string user, string pass, string email)
    {
        List<hachiModel.PR_Category> cates = catectr.GetCategoriesCanUse();
        // Return JSON data
        //string[][] JaggedArray = new string[cates.Count][];
        JavaScriptSerializer js = new JavaScriptSerializer();
        string strJSON = js.Serialize(cates.Select(s => new { s.ParentID, s.CategoryID, s.CategoryCode }));
        return strJSON;
    }
    #endregion

    #region change pass
    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public string changePass(string user, string oldpass, string newpass)
    {
        List<hachiModel.PR_Category> cates = catectr.GetCategoriesCanUse();
        // Return JSON data
        //string[][] JaggedArray = new string[cates.Count][];
        JavaScriptSerializer js = new JavaScriptSerializer();
        string strJSON = js.Serialize(cates.Select(s => new { s.ParentID, s.CategoryID, s.CategoryCode }));
        return strJSON;
    }
    #endregion

}
